package cn.bisoft.java.service.ext.httpclient;

import java.util.Map;

import cn.bisoft.java.constants.Constants;
import cn.bisoft.java.core.Facade;
import cn.bisoft.java.core.Spring;
import cn.bisoft.java.service.ext.httpclient.core.BaseHttpService;
import cn.bisoft.java.service.ext.httpclient.core.HttpService;

public class HttpClientFacade implements Facade
{
	private HttpService httpService;

	public String doPost(String uri, Map<String, String> paramsMap, String encode)
	{
		httpService = (HttpService) Spring.getBean("httpService");

		((BaseHttpService) httpService).setUri(uri);
		((BaseHttpService) httpService).setPostParams(paramsMap, encode);

		httpService.sendRequest();

		return httpService.getResponse();
	}

	public String doGet(String uri, Map<String, String> paramsMap)
	{
		httpService = (HttpService) Spring.getBean("httpService");

		((BaseHttpService) httpService).setUri(uri);
		((BaseHttpService) httpService).setGetParams(paramsMap);

		httpService.sendRequest();

		return httpService.getResponse();
	}

	public static void main(String[] args) throws Exception
	{
		Spring.loadApplicationContext();

		HttpClientFacade httpClientFacade = (HttpClientFacade) Spring.getBean("httpClientFacade");

		httpClientFacade.doGet("/", null);
		httpClientFacade.doPost("/", null, Constants.GBK);

	}

}
